
#ifndef __VTY_CLIENT_MANAGER_HPP__
#define __VTY_CLIENT_MANAGER_HPP__ 

#include "khan.hpp"
#include "vty.hpp"
#include "ipc_session.hpp"
#include "vty_ipc_msg.hpp"
#include "cmd_mng_session.hpp"
#include "cmd_mng_client.hpp"

class vty_client_manager;
typedef boost::shared_ptr<vty_client_manager> vty_client_manager_ptr;

class vty_client_manager
: public boost::enable_shared_from_this<vty_client_manager>,
private boost::noncopyable       
{
public:
    static vty_client_manager_ptr instance() 
    {
        if (_instance.use_count() == 0) { 
            boost::mutex::scoped_lock scoped_lock(_singleton_lock);
            if (_instance.use_count() == 0) 
                _instance.reset(new vty_client_manager());
        }
        return _instance;
    }
    ~vty_client_manager() { PDBG("delete vty_client_manager\n"); }

    //command_manager_if_ptr get_cmd_mng() { return _cmdmng; };   /* FIXME */

    void run() {
        _ioserv.run();
    }

    void stop() {
        _ioserv.stop();
    }

    void register_func(__u64 func_id, ExcuteHandle func) {
        _func_map[func_id] = func;
    }
    ExcuteHandle find_func(__u64 func_id) {
        return _func_map[func_id];
    };

private:
    typedef std::map<__u64, ExcuteHandle> func_map_t;

    vty_client_manager()
    {
        PDBG("create vty_client_manager\n");
    }

    static vty_client_manager_ptr _instance;
    static boost::mutex _singleton_lock;
    func_map_t  _func_map;
    io_service  _ioserv;
};


vty_client_manager_ptr vty_client_manager::_instance;
boost::mutex vty_client_manager::_singleton_lock;

#endif /* __VTY_CLIENT_MANAGER_HPP__ */
